package com.bjsxt.controller.statistics;

import cn.hutool.core.date.DateUtil;
import com.bjsxt.controller.BaseController;
import com.bjsxt.domain.Workload;
import com.bjsxt.domain.WorkloadStat;
import com.bjsxt.dto.WorkloadQueryDto;
import com.bjsxt.service.WorkloadService;
import com.bjsxt.vo.AjaxResult;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工作量统计分析controller层
 */
@RestController
@RequestMapping("statistics/workload")
public class WorkloadController extends BaseController{

    @Reference
    private WorkloadService workloadService;

    /**
     * 医生工作量统计列表
     *
     * @param workloadQueryDto
     * @return
     */
    @GetMapping("queryWorkload")
    @HystrixCommand
    public AjaxResult queryWorkload(WorkloadQueryDto workloadQueryDto) {
        if (workloadQueryDto.getBeginTime() == null) {
            workloadQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<Workload> workloads = this.workloadService.queryWorkload(workloadQueryDto);
        return AjaxResult.success(workloads);
    }

    /**
     * 总体工作量统计列表ic
     *
     * @param workloadQueryDto
     * @return
     */
    @GetMapping("queryWorkloadStat")
    @HystrixCommand
    public AjaxResult queryWorkloadStat(WorkloadQueryDto workloadQueryDto) {
        if (workloadQueryDto.getBeginTime() == null) {
            workloadQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<WorkloadStat> workloadStats = this.workloadService.queryWorkloadStat(workloadQueryDto);
        return AjaxResult.success(workloadStats);
    }
}